package com.wei.miaosha.dao;

import com.wei.miaosha.domain.MiaoshaGoods;
import com.wei.miaosha.vo.GoodsVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * Created by Weizichen on 2018/8/4.
 * desc:user接口
 */
@Mapper
public interface GoodsDao {
    @Select("SELECT g.*,mg.stock_count,mg.start_date,mg.end_date,mg.miaosha_price FROM goods g,miaosha_goods mg WHERE g.id=mg.goods_id")
        //List<GoodsVo> ListGoodsVo(@Param("id") int id);
    List<GoodsVo> ListGoodsVo();

    @Select("SELECT g.*,mg.stock_count,mg.start_date,mg.end_date,mg.miaosha_price FROM goods g,miaosha_goods mg WHERE g.id=mg.goods_id AND mg.goods_id=#{goodsId}")
    GoodsVo getGoodsVoByGoodsId(@Param("goodsId") long goodsId);

    @Update("update miaosha_goods set stock_count = stock_count - 1 where goods_id = #{goodsId} and stock_count>0")
    int reduceStock(MiaoshaGoods miaoshaGoods);
}
